<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>欢迎页面-X-admin2.2</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="stylesheet" th:href="@{/css/font.css}">
  <link rel="stylesheet" th:href="@{/css/xadmin.css}">
  <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
  <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>

<body style="background-color: #FFFAE3">
<div class="x-nav" style="height: 43px;background-color: #FFFAE3">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
          </span>
</div>
<div className="layui-btn-container" style="font-size: 20px;font-weight: bold;width: 500px;margin-left: 560px;background-color: #FFFAE3" id="divLeft" >
  合同申请审批一览表
</div>
<div id="div1">
  <table style="margin-left: 10px;background-color: #FFFAE3" class="layui-hide" id="text" lay-filter="demo" ></table>
</div>
<div id="div2">
  <input type="hidden" id="id">
  <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
      <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
  </div>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body layui-table-body layui-table-main">
            <!--<table class="layui-table layui-form" id="test"></table>-->
            <TABLE class="layui-table layui-form" style="LINE-HEIGHT: 30px" cellSpacing=1 cellPadding=0
                   width="100%" bgColor=#336699 borderColorLight=#006699 border=0>
              <TBODY>
              <TR>
                <TD>
                  <TABLE class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>
                    <TBODY>
                    <TR bgColor=#ffffff>
                      <TD align=middle width="100%" bgColor=#ffffff colSpan=20
                          height=22>
                        <H2 style="color: #0070c0"><B>编辑合同申请</B></H2>
                      </TD>
                    </TR>
                    <TR class=t1>
                      <TD width="20%" hidden>询价书编号：</TD>
                      <TD class=t2 width="30%" id="enquireId" hidden></TD>
                      <TD width="20%">询价书名称：</TD>
                      <TD class=t2 width="30%">
                        <A href="javascript:alert('对应询价书详细')" id="enquireName3"></A>
                      </TD>
                      <TD width="20%">报价份数：</TD>
                      <TD class=t2 width="30%" id="statQuote"></TD>
                    </TR>
                    <TR class=t1>
                      <TD width="20%">最高报价（元）：</TD>
                      <TD class=t2 width="30%" id="topQuote"></TD>
                      <TD width="20%">最低报价（元）：</TD>
                      <TD class=t2 width="30%" id="lowQuote"></TD>
                    </TR>
                    </TBODY>
                  </TABLE>
                </TD>
              </TR>
              </TBODY>
            </TABLE>

            <TABLE class="layui-table layui-form" style="LINE-HEIGHT: 30px" cellSpacing=1 cellPadding=0
                   width="100%" bgColor=#336699 borderColorLight=#006699 border=0>
              <TBODY>
              <TR>
                <table id="tableContract" class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>

                </table>
                <TD>
                  <table  class="layui-table layui-form" cellSpacing=1 cellPadding=3 width="100%" border=0>
                    <tbody >
                    <tr class=t1>
                      <td align=middle><B>需求计划数量</B></td>
                      <td align=middle id="orderNum"></td>
                      <td align=middle><B>订货计划数量</B></td>
                      <td align=middle id="dingHuoNum"></td>
                    </tr>
                    <tr class=t1>
                      <td align=middle>总金额（元）</td>
                      <td align=middle colspan="3" id="sumPrice"></td>
                    </tr>
                    <tr>
                      <td>部长是否同意</td>
                      <td colspan="3" style="text-align: center" id="leadAgree">
                        <input type="radio" name="approval" value="同意" title="同意">
                        <input type="radio" name="approval" value="驳回" title="驳回">
                        <input type="radio" name="approval" value="废弃" title="废弃">
                      </td>
                    </tr>
                    <tr>
                      <td >部长审核意见</td>
                      <td colspan="3">
                        <textarea id="leadOpinion" name="opinion" required lay-verify="required" placeholder="请输入" class="layui-textarea"></textarea>
                      </td>
                    </tr>
                    </tbody>
                  </table>
                </TD>
              </TR>
              </TBODY>
            </TABLE>

            <BR>
            <div style="text-align: center">
              <INPUT onclick="location.href='/contractmanager/Confirmcontractapplication.html' " type="button" value="返回">
              <button onclick="TiJiao()">提交</button>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>

</body>

<script id="button" type="text/html">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">审批</a>
</script>

<script>
  let data;
  layui.use('table', function () {
    $("#div2").hide();
    var table = layui.table;
    table.render({
      elem: '#text'  //html中渲染table的id
      , url: '/contractmanager/DaiShen'   //后台获取数据集合的地址
      , cellMinWidth: 80
      , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
        layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
        //,curr: 5 //设定初始在第 5 页
        , groups: 1 //只显示 1 个连续页码
        , first: false//不显示首页
        , last: false //不显示尾页

      }, cols: [
        [
          //表单显示的title以及返回的需要显示的数据，field值与获取集合中的类的字段名一致。
          {field: 'id', sort: true, title: '序号', align: 'center'}
          , {field: 'contAppNum',  title: '合同申请编号', align: 'center'}
          , {field: 'author', title: '编制人', align: 'center'}
          , {field: 'topQuote', sort: true, title: '最高报价', align: 'center'}
          , {field: 'lowQuote', title: '最低报价', align: 'center'}
          , {field: 'allSumPrice', sort: true, title: '总金额', align: 'center'}
          , {field: 'status', sort: true, title: '状态', align: 'center'}
          , {fixed: 'right', width: 220, title: '操作', toolbar: "#button", align: 'center'}
        ]
      ]
    });

    table.on('tool(demo)', function (obj) {
      if(obj.event=='detail'){
        let data = obj.data;
        $("#div1").hide();
        $("#div2").show();
        $.ajax({
          url:'/contractmanager/findContAppById',
          data:{"id":data.id},
          type:'post',
          success:function (result) {
            $("#enquireName3").html(result.contAppNum);
            $("#statQuote").html(result.statQuote);
            $("#topQuote").html(result.topQuote);
            $("#lowQuote").html(result.lowQuote);
            $("#sumPrice").html(result.allSumPrice);
            $("#id").val (result.id);
            $.ajax({
              url:'/contractmanager/findContAppId',
              data:{"id":result.id},
              type:'post',
              success:function (result1) {
                $("#orderNum").html(result1.length);
                let dinghuoNum=0.00;
                for (let i=0;i<result1.length;i++) {
                  dinghuoNum+=Number(result1[i].amount);
                  $("#tableContract").append(
                          "<TR class=T1>\n" +
                          "                                                <TD noWrap align=middle colSpan=9>\n" +
                          "                                                    物资\n" +
                          "                                                    <B style='color: red'>"+(Number(i)+1)+" &nbsp;\n" +
                          "                                                    </B><A href=\"javascript:alert('对应需求计划书详细')\" style='color: blue'>"+result1[i].materialName+"</A>\n" +
                          "                                                    "+result1[i].amount+"个\n" +
                          "                                                    <B>计划价（元/含税）</B>\n" +
                          "                                                    \n" +
                          "                                                    <A\n" +
                          "                                                        href=\"javascript:alert('对应报价书详细')\"> 报价明细信息</A>&nbsp;&nbsp;\n" +
                          "                                                </TD>\n" +
                          "                                            </TR>\n" +
                          "                                            <TR class=t1>\n" +
                          "                                                <TD noWrap align=middle width=\"20%\">供应商编号</TD>\n" +
                          "                                                <TD noWrap align=middle>数量</TD>\n" +
                          "                                                <TD noWrap align=middle>单价<BR>（元/含税）</TD>\n" +
                          "                                                <TD noWrap align=middle>运杂费<BR>（元）</TD>\n" +
                          "                                                <TD noWrap align=middle>其它费用<BR>（元）</TD>\n" +
                          "                                                <TD noWrap align=middle>总计<BR>（元）</TD>\n" +
                          "                                                <TD noWrap align=middle>开始<BR>交货期</TD>\n" +
                          "                                                <TD noWrap align=middle>结束<BR>交货期</TD>\n" +
                          "                                            </TR>\n"+"                                            <TR class=t2>\n" +
                          "                                                <TD style='text-align: center' width=\"20%\">"+result1[i].supplierId+"<BR></TD>\n" +
                          "                                                <TD align=right>"+result1[i].amount+"<BR></TD>\n" +
                          "                                                <TD align=right>"+result1[i].unitPrice+"<BR></TD>\n" +
                          "                                                <TD style='text-align: center'  align=right>"+result1[i].mixPrice+"<BR></TD>\n" +
                          "                                                <TD style='text-align: center'  align=right>"+result1[i].otherPrice+"<BR></TD>\n" +
                          "                                                <TD style='text-align: center'  align=right>"+result1[i].totalPrice+"<BR></TD>\n" +
                          "                                                <TD style='text-align: center' >"+result1[i].startDate+"<BR></TD>\n" +
                          "                                                <TD style='text-align: center' >"+result1[i].endDate+"<BR></TD>\n" +
                          "                                            </TR>")
                }

                $("#dingHuoNum").html(dinghuoNum);
              }

            })
          }
        })
      }
    });
  });
  function Fan(){
    $("#div1").show();
    $("#div2").hide();
  }
  function TiJiao(){
    let ssStatic=$("input[name='approval']:checked").val()
    let leadOpinion=$("#leadOpinion").val()
    $.ajax({
      url: "/contractmanager/UpdateByIdPr",
      data: {
        "id": $.trim($("#id").val()),
        "status": ssStatic,
        "leadOpinion": leadOpinion
      },
      type: "POST",
      success: function (result) {
        if (result === true) {
          layer.alert("提交成功!")
          setTimeout(() => {
            location.reload()
          }, 1000)
        } else {
          layer.alert("提交失败!")
        }
      }
    });
  }
</script>

</html>